import base64

from mitmproxy import http
from mitmproxy.net.server_spec import ServerSpec
# 代理信息
proxy_ip="168.158.59.42"
proxy_port=44445
proxy_username="14afbec1061be"
proxy_password="7e458caded"



class ProxyManager:
    def request(self,flow: http.HTTPFlow):

        flow.server_conn.via = ServerSpec(("https",proxy_ip,proxy_port))

        credentials = f"{proxy_username}:{proxy_password}"
        encoded_credentials = base64.b64encode(credentials.encode()).decode()
        flow.request.headers["Proxy-Authorization"] = f"Basic {encoded_credentials}"
